//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.chris.impl;

import com.chris.entity.register;
import com.chris.utils.DbConnection;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

public class registerImpl {
    private final QueryRunner runner = new QueryRunner();

    public registerImpl() {
    }

    public List<register> getByTitle(String title) throws SQLException {
        String sql = "select * from register where journal_title=? order by year,volume,issue";
        Connection connection = DbConnection.getConnection();
        return this.runner.query(connection, sql, new BeanListHandler<>(register.class), title);
    }

    public register getByID(int id) throws SQLException {
        String sql = "select * from register where journal_id = ? order by year,volume,issue";
        Connection connection = DbConnection.getConnection();
        return this.runner.query(connection, sql, new BeanHandler<>(register.class), id);
    }

    public void Borrowed(int id, int statue) {
        String sql = "update register set borrowed = ? where journal_id = ?";
        Connection connection = DbConnection.getConnection();

        try {
            this.runner.execute(connection, sql, statue, id);
        } catch (SQLException var6) {
            var6.printStackTrace();
        }

    }
    public List<register> getAll() throws SQLException{
        String sql = "select * from register order by year,volume,issue";
        Connection connection = DbConnection.getConnection();
        return this.runner.query(connection, sql, new BeanListHandler<>(register.class));
    }

    public void insert(String journal_title, int year, int volume, int issue, int borrowed) throws SQLException {
        String sql = "insert into register (journal_title,year,volume,issue,borrowed) values(?,?,?,?,?)";
        Connection connection = DbConnection.getConnection();
        this.runner.execute(connection, sql, journal_title, year, volume, issue, borrowed);
    }
}
